package com.jumei.flume.parser;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.List;

/**
 * 解析之后的日志行信息，主要用来为格式化数据文本准备，例如hive数据中的一行信息
 */
public class ParsedLine {


    /**
     * 日志行所属分类
     */
    private String category;
    private boolean singleLineFlag = true;
    private DateTime createTime;
    private String logSizeType;

    //添加一个备用参数
    private String standbyParam;

    private static DateTimeFormatter yearFmt = DateTimeFormat.forPattern("yyyy");
    private static DateTimeFormatter yearMonthFmt = DateTimeFormat.forPattern("yyyyMM");
    private static DateTimeFormatter dateFmt = DateTimeFormat.forPattern("yyyyMMdd");
    private static DateTimeFormatter monthFmt = DateTimeFormat.forPattern("MM");
    private static DateTimeFormatter hourFmt = DateTimeFormat.forPattern("HH");

    /**
     * 解析并格式化之后的一行数据
     */
    private String line;

    /**
     * 解析并格式化之后的多行数据
     * 注：部分日志中的一行的信息实际反应了多条数据，故需解析成多行
     */
    private List<String> lines;

    public ParsedLine(String category) {
        this.category = category;
        this.singleLineFlag = true;
    }

    public ParsedLine(String category, boolean singleLineFlag) {
        this.category = category;
        this.singleLineFlag = singleLineFlag;
    }

    public String getCategory() {
        return category;
    }

    public String getLine() {
        return line;
    }

    public void setLine(String line) {
        this.line = line;
    }

    public List<String> getLines() {
        return lines;
    }

    public void setLines(List<String> lines) {
        this.lines = lines;
    }

    public DateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(DateTime createTime) {
        this.createTime = createTime;
    }

    public boolean isSingleLine() {
        return this.singleLineFlag;
    }

    public String getCreateYearString() {
        if (this.createTime != null) {
            return this.createTime.toString(yearFmt);
        }
        return "";
    }

    public String getCreateYearMonthString() {
        if (this.createTime != null) {
            return this.createTime.toString(yearMonthFmt);
        }
        return "";
    }

    public String getCreateDateString() {
        if (this.createTime != null) {
            return this.createTime.toString(dateFmt);
        }
        return "";
    }

    public String getCreateHourString() {
        if (this.createTime != null) {
            return "" + this.createTime.toString(hourFmt);
        }
        return "";
    }

    public String getCreateMonthString() {
        if (this.createTime != null) {
            return "" + this.createTime.toString(monthFmt);
        }
        return "";
    }

    public String getCreateDayString() {
        if (this.createTime != null) {
            return "" + this.createTime.getDayOfMonth();
        }
        return "";
    }

    public String getLogSizeType() {
        return logSizeType;
    }

    public void setLogSizeType(String logSizeType) {
        this.logSizeType = logSizeType;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getStandbyParam() {
        return standbyParam;
    }

    public void setStandbyParam(String standbyParam) {
        this.standbyParam = standbyParam;
    }
}
